<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人资料 - AI简历分析系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        :root {
            --primary-color: #4e73df;
            --secondary-color: #858796;
            --success-color: #1cc88a;
            --info-color: #36b9cc;
            --warning-color: #f6c23e;
            --danger-color: #e74a3b;
            --light-color: #f8f9fc;
            --dark-color: #5a5c69;
        }

        body {
            font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background-color: #f8f9fc;
        }

        .sidebar {
            background: linear-gradient(180deg, var(--primary-color) 0%, #224abe 100%);
            min-height: 100vh;
            color: white;
            transition: all 0.3s;
        }

        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.8);
            margin: 5px 0;
            border-radius: 5px;
            padding: 10px 15px;
        }

        .sidebar .nav-link:hover {
            color: white;
            background-color: rgba(255, 255, 255, 0.1);
        }

        .sidebar .nav-link.active {
            color: white;
            background-color: rgba(255, 255, 255, 0.2);
        }

        .sidebar .nav-link i {
            margin-right: 10px;
        }

        .topbar {
            height: 70px;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
            background-color: white;
        }

        .card {
            border: none;
            border-radius: 0.35rem;
            box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.1);
            margin-bottom: 20px;
        }

        .card-header {
            background-color: #f8f9fc;
            border-bottom: 1px solid #e3e6f0;
            padding: 1rem 1.35rem;
            font-weight: 600;
        }

        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            object-fit: cover;
        }

        .content-wrapper {
            padding: 20px;
        }

        /* 个人资料页面特定样式 */
        .profile-management-container {
            background-color: #f5f5f5;
            min-height: calc(100vh - 90px);
            padding: 20px;
            font-family: Arial, sans-serif;
        }

        .top-control-bar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
            padding: 0 20px;
        }

        .page-title {
            font-size: 24px;
            font-weight: bold;
            color: #333;
        }

        .settings-icon {
            width: 24px;
            height: 24px;
            cursor: pointer;
            background-color: #666;
            border-radius: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
        }

        .user-info-card {
            background: white;
            border-radius: 12px;
            padding: 24px;
            margin: 0 auto 30px;
            max-width: 400px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .avatar-section {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .circular-avatar {
            width: 60px;
            height: 60px;
            border-radius: 50%;
            background-color: #007bff;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            font-weight: bold;
            margin-right: 16px;
        }

        .avatar-image {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            object-fit: cover;
        }

        .user-details {
            flex: 1;
        }

        .username {
            font-size: 18px;
            font-weight: bold;
            color: #333;
            margin-bottom: 4px;
        }

        .email {
            font-size: 14px;
            color: #666;
            margin-bottom: 8px;
        }

        .sync-status {
            font-size: 12px;
            color: #28a745;
            font-weight: 500;
        }

        .avatar-modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
        }

        .modal-content {
            background-color: white;
            margin: 10% auto;
            padding: 20px;
            border-radius: 8px;
            width: 80%;
            max-width: 500px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
        }

        .avatar-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 15px;
            margin-top: 15px;
        }

        .avatar-option {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            cursor: pointer;
            border: 3px solid transparent;
            transition: border-color 0.3s;
        }

        .avatar-option:hover {
            border-color: #007bff;
        }

        .avatar-option.selected {
            border-color: #28a745;
        }

        .modal-actions {
            display: flex;
            justify-content: flex-end;
            margin-top: 20px;
            gap: 10px;
        }

        .modal-btn {
            padding: 8px 16px;
            border-radius: 4px;
            cursor: pointer;
        }

        .confirm-btn {
            background-color: #007bff;
            color: white;
            border: none;
        }

        .cancel-btn {
            background-color: #f8f9fa;
            border: 1px solid #ddd;
        }

        .action-area {
            background: white;
            border-radius: 12px;
            padding: 20px;
            margin: 0 auto;
            max-width: 400px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .action-button {
            display: flex;
            align-items: center;
            padding: 16px;
            border: none;
            background: none;
            width: 100%;
            text-align: left;
            cursor: pointer;
            border-radius: 8px;
            margin-bottom: 12px;
            transition: background-color 0.2s;
        }

        .action-button:hover {
            background-color: #f8f9fa;
        }

        .action-icon {
            width: 24px;
            height: 24px;
            margin-right: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 16px;
        }

        .action-text {
            font-size: 16px;
            color: #333;
        }

        .create-icon {
            background-color: #28a745;
            color: white;
            border-radius: 4px;
        }

        .switch-icon {
            background-color: #6c757d;
            color: white;
            border-radius: 4px;
        }

        .back-button {
            color: #1d2223;
            text-decoration: none;
            margin-right: 15px;
            font-size: 16px;
        }

        .back-button:hover {
            text-decoration: underline;
        }

        .change-avatar-button {
            margin-top: 10px;
            padding: 8px 16px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        @media (min-width: 768px) {
            .sidebar {
                width: 14rem !important;
            }
        }
    </style>
</head>
<body>
<div class="d-flex">
    <!-- 侧边栏导航 -->
    <div class="sidebar flex-shrink-0 p-3" style="width: 250px;">
        <div class="d-flex align-items-center mb-3 mb-md-0 me-md-auto text-white text-decoration-none">
            <span class="fs-4">AI简历分析系统</span>
        </div>
        <hr>
        <ul class="nav nav-pills flex-column mb-auto">
            <li class="nav-item">
                <a th:href="@{/admin/interview_admin}" class="nav-link">
                    <i class="bi bi-speedometer2"></i>
                    控制面板
                </a>
            </li>
            <li>
                <a th:href="@{/admin/users}" class="nav-link">
                    <i class="bi bi-people"></i>
                    用户管理
                </a>
            </li>
            <li>
                <a th:href="@{/admin/profile}" class="nav-link active">
                    <i class="bi bi-person"></i>
                    个人资料
                </a>
            </li>
            <li>
                <a th:href="@{/admin/setup}" class="nav-link">
                    <i class="bi bi-gear"></i>
                    系统设置
                </a>
            </li>
            <li>
                <a th:href="@{/interview}" class="nav-link">
                    <i class="bi bi-file-earmark-text"></i>
                    简历分析
                </a>
            </li>
        </ul>
    </div>

    <div class="flex-grow-1">
        <!-- 顶部导航栏 -->
        <nav class="topbar mb-4 static-top shadow">
            <div class="container-fluid d-flex justify-content-end align-items-center h-100">
                <div class="d-flex align-items-center">
                    <div class="me-3">
                        <span class="text-dark" th:text="${currentUser.username} + ' (' + ${currentUser.email} + ')'"></span>
                    </div>
                    <div class="dropdown">
                        <a href="#" class="d-flex align-items-center text-decoration-none dropdown-toggle" id="dropdownUser" data-bs-toggle="dropdown" aria-expanded="false">

                            <div th:unless="${currentUser.avatarUrl}" class="user-avatar bg-primary text-white d-flex align-items-center justify-content-center">
                                <span th:text="${currentUser.email?.substring(0,1)?.toUpperCase()}"></span>
                            </div>
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end shadow" aria-labelledby="dropdownUser">
                            <li><a class="dropdown-item" th:href="@{/admin/profile}">个人资料</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" th:href="@{/logout}">退出登录</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </nav>

        <!-- 内容区 -->
        <div class="content-wrapper">
            <div class="container-fluid">
                <!-- 个人资料内容 -->
                <div class="profile-management-container">

                    <!-- 用户信息卡片 -->
                    <div class="user-info-card">
                        <div class="avatar-section">
                            <div class="circular-avatar">


                                <th:block th:unless="${currentUser.avatarUrl != null and currentUser.avatarUrl != ''}">

                                </th:block>
                            </div>
                            <div class="user-details">
                                <div class="username" th:text="${currentUser.username != null} ? ${currentUser.username} : '个人'">个人</div>
                                <div class="email" th:text="${currentUser.email}">tsuuuuuuuki@outlook.com</div>
                                <div class="sync-status">同步已启用</div>
                            </div>
                        </div>

                        <button class="change-avatar-button" onclick="openAvatarModal()">更改头像</button>

                        <!-- 显示操作结果消息 -->
                        <div th:if="${success}" style="color: green; margin-top: 10px;" th:text="${success}"></div>
                        <div th:if="${error}" style="color: red; margin-top: 10px;" th:text="${error}"></div>
                    </div>

                    <div id="avatarModal" class="avatar-modal">
                        <div class="modal-content">
                            <h3>选择头像</h3>
                            <div class="avatar-grid">
                                <!-- 预定义的头像选项 -->
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar1" value="/static/images/img_01.png">
                                    <label for="avatar1">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar2" value="/static/images/img_02.png">
                                    <label for="avatar2">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar3" value="/static/images/img_03.png">
                                    <label for="avatar3">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar4" value="/static/images/img_04.jpg">
                                    <label for="avatar4">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar5" value="/static/images/img_05.jpg">
                                    <label for="avatar5">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar6" value="/static/images/img_06.jpg">
                                    <label for="avatar6">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar7" value="/static/images/img_07.jpg">
                                    <label for="avatar7">

                                    </label>
                                </div>
                                <div>
                                    <input type="radio" name="avatarOption" id="avatar8" value="/static/images/img_08.jpg">
                                    <label for="avatar8">

                                    </label>
                                </div>
                            </div>
                            <div class="modal-actions">
                                <button class="modal-btn cancel-btn" onclick="closeAvatarModal()">取消</button>
                                <button class="modal-btn confirm-btn" onclick="confirmAvatarSelection()">确认</button>
                            </div>
                        </div>
                    </div>

                    <!-- 操作功能区 -->
                    <div class="action-area">
                        <button class="action-button" onclick="createNewProfile()">
                            <div class="action-icon create-icon">+</div>
                            <div class="action-text">创建新的个人资料</div>
                        </button>

                        <button class="action-button" onclick="switchProfile()">
                            <div class="action-icon switch-icon">⇄</div>
                            <div class="action-text">其他配置文件</div>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    // 打开头像选择弹窗
    function openAvatarModal() {
        document.getElementById('avatarModal').style.display = 'block';
    }

    // 关闭头像选择弹窗
    function closeAvatarModal() {
        document.getElementById('avatarModal').style.display = 'none';
    }

    // 确认头像选择
    function confirmAvatarSelection() {
        const selectedAvatar = document.querySelector('input[name="avatarOption"]:checked');
        if (selectedAvatar) {
            // 提交表单
            const form = document.createElement('form');
            form.method = 'post';
            form.action = '/admin/profile/select-avatar';

            const input = document.createElement('input');
            input.type = 'hidden';
            input.name = 'avatarUrl';
            input.value = selectedAvatar.value;

            form.appendChild(input);
            document.body.appendChild(form);
            form.submit();
        } else {
            alert('请选择一个头像');
        }
    }

    // 头像选项点击事件
    document.addEventListener('DOMContentLoaded', function() {
        const avatarOptions = document.querySelectorAll('.avatar-option');
        avatarOptions.forEach(option => {
            option.addEventListener('click', function() {
                const radio = this.previousElementSibling;
                radio.checked = true;

                // 移除其他选中样式
                avatarOptions.forEach(opt => opt.classList.remove('selected'));
                // 添加当前选中样式
                this.classList.add('selected');
            });
        });
    });

    function createNewProfile() {
        console.log('创建新配置文件');
    }

    function switchProfile() {
        console.log('切换配置文件');
    }
</script>
</body>
</html>